package com.prs.crm.dao.sys.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.sys.UIResourceDao;
import com.prs.crm.domain.sys.SettleAccountDate;
import com.prs.crm.domain.sys.UIResource;

public class UIResourceDaoImpl extends BaseDaoImpl<UIResource> implements
		UIResourceDao {

	@SuppressWarnings("unchecked")
	public void setHome(UIResource resouce) {
		this.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException {
				session.createQuery("update UIResource set home=?")
						.setParameter(0, false).executeUpdate();
				return null;
			}
		});
		resouce.setHome(true);
		this.save(resouce);
	}

	@Override
	public UIResource getUIResource(String url) {
		Criteria criteria=this.getSession().createCriteria(UIResource.class);
		criteria.add(Restrictions.eq("url", url));
		List result=criteria.list();
		if(result==null||result.size()==0){
			return null;
		}
		return (UIResource) criteria.list().get(0);
	}

	
}
